﻿using JX.Application;
using JX.Core.Entity;
using JX.Infrastructure.Common;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml;

namespace JXWebSite.Areas.Admin.Components
{
	/// <summary>
	/// 公司查看视图组件
	/// </summary>
	[ViewComponent(Name = "CompanyView")]
	public class CompanyViewViewComponent : ViewComponent
	{
		private IDictionaryServiceAppDapper _DictionaryServiceApp;
		/// <summary>
		/// 依赖注入
		/// </summary>
		/// <param name="DictionaryServiceApp"></param>
		public CompanyViewViewComponent(IDictionaryServiceAppDapper DictionaryServiceApp)
		{
			_DictionaryServiceApp = DictionaryServiceApp;
		}
		/// <summary>
		/// 异步调用
		/// </summary>
		/// <param name="viewModel"></param>
		/// <returns></returns>
		public async Task<IViewComponentResult> InvokeAsync(CompanyViewModel viewModel = null)
		{
			viewModel = await GetViewModelAsync(viewModel);

			//行业地位
			ViewBag.StatusInField = _DictionaryServiceApp.GetDictionaryFieldValue("Company", "StatusInField")[viewModel.Company.StatusInField.ToInt32()].DataTextField;
			//公司规模
			ViewBag.CompanySize = _DictionaryServiceApp.GetDictionaryFieldValue("Company", "CompanySize")[viewModel.Company.CompanySize.ToInt32()].DataTextField;
			//经营状态
			ViewBag.ManagementForms = _DictionaryServiceApp.GetDictionaryFieldValue("Company", "ManagementForms")[viewModel.Company.ManagementForms.ToInt32()].DataTextField;

			return View(viewModel);
		}

		private Task<CompanyViewModel> GetViewModelAsync(CompanyViewModel viewModel)
		{
			if (viewModel == null)
			{
				viewModel = new CompanyViewModel();
			}
			return Task.FromResult(viewModel);
		}
	}
}
